package com.bawei.mvvmdemo.databindingdemo;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.mvvmdemo.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;

import androidx.databinding.BindingAdapter;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/13 11:07
 * @Description : ImageViewAdapter 图片适配器
 */
public class ImageViewAdapter {
    /**
     * 方法public static
     * @BindingAdapter注解必须有  image为ImageView设置属性
     * @param imageView
     * @param url
     */
    @BindingAdapter("image111")
    public static void setImage(ImageView imageView,String url){
        if(TextUtils.isEmpty(url)){
            imageView.setImageResource(R.drawable.ic_launcher_background);
        }else{
            Glide.with(imageView)
                    .load(url)
                    .transform(new CenterCrop())
                    .into(imageView);
        }
    }

    /**
     * 方法public static
     * @BindingAdapter注解必须有  image为ImageView设置属性
     * @param imageView
     * @param url
     */
    @BindingAdapter("image222")
    public static void setCircleImage(ImageView imageView,String url){
        if(TextUtils.isEmpty(url)){
            imageView.setImageResource(R.drawable.ic_launcher_background);
        }else{
            Glide.with(imageView)
                    .load(url)
                    .transform(new CircleCrop())
                    .into(imageView);
        }
    }
}
